<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_ad/model')->方法名();
*/
namespace jy_ad;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function current_level_up_types(){
		return str_array($this->setting['level_up_types']);
	}
	public function team_level_up_types(){
		return str_array($this->teamsetting['level_up_types']);
	}
	public function get_placement_id($adwei=1){
		$goods=$this->get('goods',array('adwei'=>$adwei,'status'=>1,'uniacid'=>$_SESSION['uniacid']));
		return $goods['placement_id'];
	}
    public function add_log($adwei=1){
	    //6小时内访问过
        $lasttime=TIMESTAMP-6*3600;
        $isadd=pdo_count('jy_ad_log',array('adwei'=>$adwei,'mid'=>$_SESSION['uid'],'createtime >'=>$lasttime),'id');
        if($isadd){
           return false;
        }
        $goods=$this->get('goods',array('adwei'=>$adwei,'status'=>1,'uniacid'=>$_SESSION['uniacid']));
        $fee=$goods['price'];
        if(!$fee<=0 || !$fee){
            return false;
            $fee=0.01;
        }
        $log=array(
            'uniacid'=>$_SESSION['uniacid'],
            'mid'=>$_SESSION['uid'],
            'goodsid'=>$goods['id'],
            'fee'=>$fee,
            'adwei'=>$adwei,
            'type'=>$goods['type'],
            'createtime'=>TIMESTAMP,
            'status'=>1,
        );
        $this->insert('log',$log);
        $log['id']=pdo_insertid();
        $this->model('team')->ad_fee($log);
        $this->model('team')->add_commission($log,3);
        $this->model('nfee')->add_fee($log);
        return true;
    }
}
?>